package com.bakerj.infinitecards.transformer;

import com.bakerj.infinitecards.AnimationTransformer;

import ohos.agp.components.Component;

/**
 * DefaultTransformerToFront
 *
 * @author BakerJ
 * @since : 2021.5.24
 */
public class DefaultTransformerToFront implements AnimationTransformer {
    @Override
    public void transformAnimation(Component view, float fraction, int cardWidth, int cardHeight,
                                   int fromPosition, int toPosition) {
        int positionCount = fromPosition - toPosition;
        float scale = (float) ((0.8F - 0.1F * (double)fromPosition) + (0.1F * (double)fraction * (double)positionCount));
        view.setScaleX(scale);
        view.setScaleY(scale);
        float alpha = (float) (180*(1 - (double)fraction));
        view.setRotation(alpha);
        if (fraction < 0.5) {
            float setTranslationY1 = (float) ((double) (-cardHeight) * (0.8F - (double) scale) * 0.5F - (double) cardWidth * 0.02F
                    * (double) fromPosition - (double) cardHeight * (double) fraction);
            view.setTranslationY(setTranslationY1);
        } else {
            float setTranslationY2 = (float) ((double) (-cardHeight) * (0.8F - (double) scale) * 0.5F - (double) cardWidth * (0.02F *
                    (double) fromPosition - 0.02F * (double) fraction * (double) positionCount) - (double) cardHeight * (1 - (double) fraction));
            view.setTranslationY(setTranslationY2);
        }
    }

    @Override
    public void transformInterpolatedAnimation(Component view, float fraction, int cardWidth,
                                               int cardHeight, int fromPosition, int toPosition) {
    }
}
